package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CutomerTransfer;
import cn.wolfcode.crm.query.CutomerTransferQueryObject;
import cn.wolfcode.crm.service.ICutomerTransferService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("cutomerTransfer")
public class CutomerTransferController {
    @Autowired
    private ICutomerTransferService cutomerTransferService;

    @RequestMapping("view")
    @RequiresPermissions(value = {"cutomerTransfer:view", "移交客户页面"}, logical = Logical.OR)
    public String view() {
        return "client/cutomerTransfer";
    }

    @RequestMapping("list")
    @ResponseBody
    public PageResult list(CutomerTransferQueryObject qo) {
        return cutomerTransferService.list(qo);
    }

    @RequestMapping("transfer")
    @ResponseBody
    @RequiresPermissions(value = {"cutomerTransfer:transfer","移交客户"},logical = Logical.OR)
    public JsonResult transfer(CutomerTransfer obj) {
        System.out.println(obj.getNewSeller());
        try {
            cutomerTransferService.transfer(obj);
            return JsonResult.success("移交成功");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.mark("移交失败");
        }
    }
}
